#include "driver_flash.h"
#include "stdlib.h"

uint32_t ReadWord(const uint32_t nAddr)
{
	return *((__IO uint32_t*)(nAddr));
}


uint16_t ReadHalfWord(const uint32_t nAddr)
{
    return *((__IO uint16_t*)(nAddr));
}

uint8_t ReadByte(const uint32_t nAddr)
{
    return *((__IO uint8_t*)(nAddr));
}

int16_t EraseAllPage(void)
{
    int16_t status = -1;
    FLASH_Unlock();
    status = FLASH_EraseAllPages();
    FLASH_Lock();
    return status;
}

int16_t ErasePage(const uint32_t nAddr)
{
    int16_t status = -1;
    FLASH_Unlock();
    status = FLASH_ErasePage(nAddr);
    FLASH_Lock();
    return status;
}

int16_t ProgramWord(const uint32_t nAddr, const uint32_t nData)
{
	int16_t status = -1;
	FLASH_Unlock();
	status = FLASH_ProgramWord(nAddr, nData);
	FLASH_Lock();
	return status;
}

int16_t ProgramHalfWord(const uint32_t nAddr, const uint16_t nData)
{
	int16_t status = -1;
	FLASH_Unlock();
	status = FLASH_ProgramHalfWord(nAddr, nData);
	FLASH_Lock();
	return status;
}


